< previous page page_143 next page >

Page 143
An easy way to use the control is to set its CancelError property to True. Then if the user cancels the printer dialog, the program receives an error. To avoid crashing, the program should use an On Error statement to trap the error.
If the user presses the dialog's OK button, the program does not receive an error. The dialog automatically updates the program's Printer object to indicate the newly selected printer. The program can examine the dialog control's properties to learn about other values specified by the user. For instance, the program can learn whether the user checked the Print to file box.
A program can set the dialog's Flags property to modify the dialog's appearance. For example, if you set the cdlPDHidePrintToFile flag, the dialog hides its Print to file check box.
Example program PickPtr, shown in Figure 5.2, uses the following code to display a printer selection dialog. If the user cancels, the program does nothing. If the user accepts the dialog, the program prints the name of the selected printer on that printer.
e10a6a0a59f035e870d90cca05b85fce.gif
' Let the user select a printer.
Private Sub cmdPickPrinter_Click()
    dlgPrinter.CancelError = True

    On Error Resume Next
    dlgPrinter.ShowPrinter
    If Err.Number = cdlCancel Then
        ' The user canceled. Do nothing.
        Exit Sub
    ElseIf Err.Number <> 0 Then
        ' Unexpected error. Report it.
0143-01.jpg
Figure 5.2
Example program PickPtr lets the user select a printer.

 
< previous page page_143 next page >